from day01.basecla import BaseClass
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from time import sleep
c=BaseClass()
c.open_browser('http://sahitest.com/demo/selectTest.htm')
locator={
    "num1":'//*[@id="s1Id"]',
    "num2":'//*[@id="s2Id"]',
    "num3":'//*[@id="s3Id"]',
    "num4":'//*[@id="s4Id"]',
    "num5":'//*[@id="s1"]',
    "num6":'//*[@id="testInputEvent"]'
}
mynum1=c.location(By.XPATH,locator['num1'])
mynum2=c.location(By.XPATH,locator['num2'])
mynum3=c.location(By.XPATH,locator['num3'])
mynum4=c.location(By.XPATH,locator['num4'])
mynum5=c.location(By.XPATH,locator['num5'])
mynum6=c.location(By.XPATH,locator['num6'])
n1=Select(mynum1)
n2=Select(mynum2)
n3=Select(mynum3)
n4=Select(mynum4)
n5=Select(mynum5)
n6=Select(mynum6)
#查看是否多选
if n1.is_multiple:
    print('n1可以多选')
else:
    print('n1不可以多选')
if n4.is_multiple:
    print('n4可以多选')
else:
    print('n4不可以多选')
#查看所有选项
list1=[]
for item1 in n4.options:
    list1.append(item1.text)
    print(list1)

n1.select_by_index(1)
sleep(1)
n2.select_by_value('o3')
sleep(1)
n3.select_by_visible_text('o2')
sleep(2)
#n4.all_selected_options
n4.select_by_index(1)
sleep(1)
n4.select_by_value('o2val')
sleep(1)
n4.select_by_visible_text('o3')
sleep(2)
n4.deselect_by_index(1)
n4.deselect_by_value('o2val')
n4.deselect_by_visible_text('o3')
c.close_browser()